package com.ruoyi.web.controller.business.order;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruoyi.business.base.PageParam;
import com.ruoyi.web.controller.business.order.factory.JbApprovalLogFactory;
import com.ruoyi.web.controller.business.order.vo.JbAuditVO;
import com.ruoyi.web.core.JoR;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.business.order.domain.JbApprovalLog;
import com.ruoyi.business.order.service.JbApprovalLogService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 审批日志（针对订单、退款等各个状态操作记录） Controller
 *
 * @author ruoyi
 * @date 2024-10-11
 */
@Api("审批日志（针对订单、退款等各个状态操作记录）")
@RestController
@RequestMapping("/approval_log")
public class JbApprovalLogController extends BaseController
{
    @Autowired
    private JbApprovalLogService service;

    @Autowired
    private JbApprovalLogFactory factory;

    /**
     * 查询审批日志（针对订单、退款等各个状态操作记录）列表
     */
    @ApiOperation("查询审批日志（针对订单、退款等各个状态操作记录）列表")
    @GetMapping("/list")
    public TableDataInfo list(PageParam page, JbApprovalLog jbApprovalLog)
    {
        return JoR.rows(factory.list(page, jbApprovalLog));
    }

    /**
     * 导出审批日志（针对订单、退款等各个状态操作记录）列表
     */
    @ApiOperation("导出审批日志（针对订单、退款等各个状态操作记录）列表")
    @Log(title = "审批日志（针对订单、退款等各个状态操作记录）", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PageParam page, JbApprovalLog jbApprovalLog)
    {
        LambdaQueryWrapper<JbApprovalLog> select = new LambdaQueryWrapper<>();
        IPage<JbApprovalLog> iPage = service.page(page.b(), select);

        List<JbApprovalLog> list = iPage.getRecords();
        ExcelUtil<JbApprovalLog> util = new ExcelUtil<JbApprovalLog>(JbApprovalLog.class);
        util.exportExcel(response, list, "审批日志（针对订单、退款等各个状态操作记录）数据");
    }

    /**
     * 获取审批日志（针对订单、退款等各个状态操作记录）详细信息
     */
    @ApiOperation("获取审批日志（针对订单、退款等各个状态操作记录）详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(service.getById(id));
    }

    /**
     * 新增审批日志（针对订单、退款等各个状态操作记录）
     */
    @ApiOperation("新增审批日志（针对订单、退款等各个状态操作记录）")
    @Log(title = "审批日志（针对订单、退款等各个状态操作记录）", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody JbApprovalLog jbApprovalLog)
    {
        return toAjax(service.save(jbApprovalLog));
    }

    /**
     * 修改审批日志（针对订单、退款等各个状态操作记录）
     */
    @ApiOperation("修改审批日志（针对订单、退款等各个状态操作记录）")
    @Log(title = "审批日志（针对订单、退款等各个状态操作记录）", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody JbApprovalLog jbApprovalLog)
    {
        return toAjax(service.updateById(jbApprovalLog));
    }

    /**
     * 删除审批日志（针对订单、退款等各个状态操作记录）
     */
    @ApiOperation("删除审批日志（针对订单、退款等各个状态操作记录）")
    @Log(title = "审批日志（针对订单、退款等各个状态操作记录）", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(service.removeByIds(Arrays.asList(ids)));
    }

}
